package scenic.jni;

import java.awt.Rectangle;

import scenic.Color;
import scenic.geom.Affine2;

public class Renderer {
	public static final int SURFACE_TYPE_COLOR = 0;
	public static final int SURFACE_TYPE_ALPHA = 1;
	public static final int SURFACE_TYPE_ALPHA2X = 2;
	public static final int SURFACE_TYPE_ALPHA4X = 3;
	
	// Images
	public native int createImage(int width, int height, int format);
	public native void deleteImage(int image);
	public native void writeImage(int image, int x, int y, int width, int height, 
			byte[] data, int offset, int pitch);

	public native void release(int context);
	
	public native boolean beginScene(int context);
	public native void endScene(int context);
	public native void present(int context);
	
	// Options
	public native void setPolygonAntialias(int context, boolean value);
	public native void setTransform(int context, double m00, double m01, 
			double m10, double m11, double dx, double dy);
	public void setTransform(int context, Affine2 t) {
		setTransform(context, t.m00, t.m01, t.m10, t.m11, t.dx, t.dy);
	}

	// Drawing
	public native void color(int context, float r, float g, float b, float a);
	public void color(int context, Color c) {
		color(context, c.red, c.green, c.blue, c.alpha);
	}
	public native void clear(int context);
	public native void drawImage(int context, int image);
	public native void solidColor(int context);
	
	public native void gradient(int context, int type, int image);

	// Text
	public native void beginText(int context);
	public native void endText(int context);
	public native void setTextTexture(int context, int image);
	public native void drawGlyph(int context, float tex_x, float tex_y, 
			float tex_width, float tex_height, int screen_x, int screen_y,
			int screen_widtht, int screen_height);
	
	// Tesselerator
	public native void tessBegin(int context);
	public native void tessEnd(int context);
	public native void tessBeginContour(int context);
	public native void tessEndContour(int context);
	public native void tessVertex(int context, double x, double y);
	
	// Line
	public native void polylineSetStyle(int context, float width, int cap, int joint, float miterLimit,
			double[] lineDashLengths, double lineDashPhase);
	public native void polylineBegin(int context, boolean closed);
	public native void polylineEnd(int context);
	public native void polylinePoint(int context, double x, double y);
	
	// Primitives
	public native void beginPrimitives(int context);
	public native void setAttribute(int context, int index, int size, byte[] data);
	public native void setAttribute(int context, int index, int size, float[] data);
	public native void setFragmentParameter(int context, int index, float[] parameter);
	public native void setTexture(int context, int index, int image);
	public native void drawIndices(int context, int type, int[] indices);
	public native void endPrimitives(int context);
	
	// Surfaces
	public native int beginSurface(int context, int x, int y, int width, int height, int type);
	public int beginSurface(int context, Rectangle bounds, int type) {
		return beginSurface(context, bounds.x, bounds.y, bounds.width, bounds.height, type);
	}
	public native void drawSurface(int context);
	public native void drawSurfaceAndClip(int context);
	public native void discardSurface(int context);
}
